﻿using System;
using AutoMapper;
using Microsoft.Practices.ServiceLocation;
using Inmobiliaria.Services.Core.DTO;
using System.Linq;
using System.Collections.Generic;
using Inmobiliaria.Base;
using Inmobiliaria.Services.Core.Interfaces;
//using Inmobiliaria.Core.DaoInterfaces;
using Inmobiliaria.Core.Domain;
using Sinalic.Core.Domain;
using Sinalic.Core.DaoInterfaces;
//using Inmobiliaria.Services.Core.Interfaces;

namespace Sinalic.UCControllers
{
    public class PersonaRules : IPersonaUC
    {
        private IDaoProvider _daoProvider;
        private IDaoPersona _daoPersona;
        private IDaoProvider DaoProvider
        {
            get
            {
                if (_daoProvider == null)
                {
                    _daoProvider = ServiceLocator.Current.GetInstance<IDaoProvider>();
                }
                return _daoProvider;
            }
        }

        private IDaoPersona DaoPersona
        {
            get
            {
                if (_daoPersona == null)
                {
                    _daoPersona = DaoProvider.GetDaoPersona();
                }
                return _daoPersona;
            }
        }


        #region IPersonaUC Members

        public DtoPersona PersonaInsert(DtoPersona dtoPersona)
        {
            if (dtoPersona == null)
            {
                throw new ArgumentNullException("dtoPersona");
            }

            var per = Mapper.Map<DtoPersona, Persona>(dtoPersona);
            per = PersonaInsert(per);
            return Mapper.Map<Persona, DtoPersona>(per);
        }

        public Persona PersonaInsert(Persona persona)
        {
            if (persona == null)
            {
                throw new ArgumentNullException("persona");
            }

            //Validar(persona);
            return DaoPersona.Save(persona);
        }
    }
        #endregion
}
